import Vue from 'vue';
import './plugins/axios';
import App from './App.vue';
import router from './router';
import store from './store';
import './plugins/element.js';
import '../src/assets/css/log.css';
import'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'

import ElementUI from "element-ui";
Vue.use(ElementUI)
Vue.config.productionTip = false

//设置axios请求头加入token
axios.interceptors.request.use(config => { 
  // debugger;
  if (config.push === '/') { 
   } else { 
    if (localStorage.getItem('tokenkye')) { 
      console.log(localStorage.getItem('tokenkye'))
      //在请求头加入token，名字要和后端接收请求头的token名字一样 
      config.headers.token=localStorage.getItem('tokenkye');  
      // config.headers['Access-Control-Allow-Origin'] = '*';
      // config.headers['Content-Type']='application/x-www-form-urlencoded';

    } 
   }
    
    return config; 
  }, 
  error => { 
   return Promise.reject(error);
  });

//响应回来token是否过期
axios.interceptors.response.use(response => { 
  //和后端token失效返回码约定403 
  if (response.data.code == 403) {
    // 引用elementui message提示框  
    ElementUI.Message({  
     message: '身份已失效', 
     type: 'err' 
     });
    //清除token 
    localStorage.removeItem('tokenkye');
    //跳转  
    router.push({name: 'login'}); 
   } else { 
     return response 
   } 
  }, 
 error => { 
  return Promise.reject(error); 
  })



new Vue({
  router,
  store,
  render: h => h(App),

}).$mount('#app')


